package com.xlh.adapter;

import java.util.List;

import com.impl.OnClickListener;
import com.xlh.Utils.Constant;
import com.xlh.Utils.FontHandler;
import com.xlh.Utils.HtmlHandler;
import com.xlh.Utils.ProtocolParser;
import com.xlh.bean.CenterText;
import com.xlh.outside.R;
import com.xlh.thread.MessageBagerTask;

import android.content.Context;
import android.text.method.LinkMovementMethod;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.graphics.Color;

import android.text.Html;
import android.widget.Toast;

import net.nightwhistler.htmlspanner.HtmlSpanner;

public class CenterAdapter extends BaseAdapter {

	private List<CenterText> data;
	private LayoutInflater mInflater;
	ViewHolder viewHolder = null;
	//private View mConvertView;
	
	public CenterAdapter(Context context , List<CenterText> data) {
		// TODO Auto-generated constructor stub
		this.data = data;
		mInflater = LayoutInflater.from(context);
		//this.mConvertView = mInflater.inflate(R.layout.center_item,parent,false);
				
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data == null? 0 : data.size();
	}

	@Override
	public CenterText getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void setData(List<CenterText> data) {
		
		if(data != null) {
			this.data = data;
		}
		this.notifyDataSetInvalidated();

		this.notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView == null) {
			//这里只会在首次初始化的时候调用
			convertView = mInflater.inflate(R.layout.center_item,parent,false);
			viewHolder = new ViewHolder();
			viewHolder.mTextView = (TextView) convertView.findViewById(R.id.center_text);
			convertView.setTag(viewHolder);

		}else{

			viewHolder = (ViewHolder) convertView.getTag();
		}


		viewHolder.mTextView.setTextColor(Color.parseColor(Constant.getAppColor().getFontColor()));

		CenterText mText = data.get(position);



		viewHolder.mTextView.setText( mText.getContent() );

		viewHolder.mTextView.setClickable(true);
		viewHolder.mTextView.setMovementMethod(LinkMovementMethod.getInstance());
		return convertView;
	}

}

class ViewHolder{
	TextView mTextView;
}
